package com.smart.lib.controller;

import com.smart.lib.entity.UserInfo;
import com.smart.lib.service.BorrowService;
import com.smart.lib.service.UserService;
import com.smart.lib.util.Pager;
import com.smart.lib.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息管理控制器层
 * */
@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    BorrowService borrowService;
    /**
     * 将根据模糊查询得到的分页数据和计算得到的页码传给前端使用
     * 提供前端调用
     * */
    @ResponseBody
    @RequestMapping(value = "/getAllUserPagerData", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getAllUserPagerDataByUsernameOrCardNo(@RequestBody Pager pager){

        return userService.getAllUserPagerDataByUsernameOrCardNo(pager);
    }

    /**
     * 添加新学生信息
     */
    @ResponseBody
    @RequestMapping(value = "/addNewStudentInfo", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response addNewStudentInfo(@RequestBody UserInfo userInfo){
        return userService.addNewUserInfo(userInfo);
    }

    /**
     * 借阅管理流程中，通过图书证二维码查询当前用户信息
     * 包括用户借阅订单内容
     * 整合信息API
     * */
    @ResponseBody
    @RequestMapping(value = "/getUserBorrowInfoByCardno", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getUserBorrowInfoByCardno(@RequestBody UserInfo userInfo){
        return userService.getUserBorrowInfoByCardno(userInfo);
    }

    /**
     * 获取指定用户借阅历史记录
     * */
    @RequestMapping(value = "/getUserBorrowHistoryData", method = RequestMethod.POST, produces = "application/json; utf-8")
    public Response getUserBorrowHistoryData(@RequestBody Pager pager){
        return borrowService.getUserBorrowHistoryData(pager);
    }
}
